/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.wholeconsulting.pacc.tests.persistance;

import ar.com.wholeconsulting.pacc.model.Fabricante;
import ar.com.wholeconsulting.pacc.model.Modelo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Duco Pablo
 */
public class AccessDBTest {

    public static void main(String[] args) {
        try {
            Set<String> fabricantes = new HashSet<String>();
            EntityManagerFactory factory = Persistence.createEntityManagerFactory("PACC");
            EntityManager manager = factory.createEntityManager();
            EntityTransaction transaction = manager.getTransaction();
            transaction.begin();

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String database = "jdbc:odbc:PACC";
            // database+= ";DriverID=22;READONLY=true}"; 
            Connection connection = DriverManager.getConnection(database, "", "");
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("select DISTINCT(Fabricante) from Modelos");
            int i=1;
            while (rs.next()) {
                Fabricante fab = new Fabricante();
                String fabName = rs.getString(1).trim().toUpperCase();
                System.out.println(i+"-"+fabName);
                ++i;
//                if (!fabName.isEmpty()) {
//                    fab.setNombre(fabName);
//                    manager.persist(fab);
//                }
            }
            rs.close();
            st.close();
            connection.close();

            transaction.commit();

            manager.close();
            factory.close();

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Error!");
        }
    }
}
